<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="generator" content="PHPDoctor 2RC4 (http://peej.github.com/phpdoctor/)">
<meta name="when" content="Fri, 23 Jul 2010 20:16:22 +0000">

<link rel="stylesheet" type="text/css" href="../stylesheet.css">
<link rel="start" href="../overview-summary.html">

<title>HR_apiResponse.class.php (Hosting Reborn API PHP Library)</title>

</head>
<body id="file" onload="parent.document.title=document.title;">

<div class="header">
<h1>Hosting Reborn API PHP Library</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source/hr_apiresponse.class.php.html" target="_top">No frames</a>
</div>
<hr>

<h1>HR_apiResponse.class.php</h1>
<hr>

<a name="line1"></a><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<a name="line2"></a><span style="color: #009933; font-style: italic;">/** &lt;p&gt;The response to a request sent from HR_api.&lt;/p&gt;
<a name="line3"></a> * &lt;p&gt;The HR_apiResponse class deserialises the API response and prepares the data to be queried by classes that extend HR_api.&lt;/p&gt;
<a name="line4"></a> * @package com\hostingreborn\api
<a name="line5"></a> *
<a name="line6"></a> * @author      Jon Cram &lt;jon@hostingreborn.com&gt;
<a name="line7"></a> * @copyright   https://api.hostingreborn.com/code/copyright/
<a name="line8"></a> * @license     https://api.hostingreborn.com/code/license/
<a name="line9"></a> * @version     1.0
<a name="line10"></a> *
<a name="line11"></a> * $Date: 2010/07/04 22:51:02 $
<a name="line12"></a> * $Revision: 2c423d307a13 $
<a name="line13"></a> *
<a name="line14"></a> *
<a name="line15"></a> */</span>
<a name="line16"></a><span style="color: #000000; font-weight: bold;">class</span> HR_apiResponse <span style="color: #009900;">&#123;</span>
<a name="line17"></a>&nbsp;
<a name="line18"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line19"></a>    <span style="color: #666666; font-style: italic;">/* Attributes                                                              */</span>
<a name="line20"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line21"></a>&nbsp;
<a name="line22"></a>&nbsp;
<a name="line23"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line24"></a>     *
<a name="line25"></a>     * @var string
<a name="line26"></a>     */</span>
<a name="line27"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$responseXML</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<a name="line28"></a>&nbsp;
<a name="line29"></a>&nbsp;
<a name="line30"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line31"></a>     *
<a name="line32"></a>     * @var DOMDocument
<a name="line33"></a>     */</span>
<a name="line34"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$responseDOM</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<a name="line35"></a>&nbsp;
<a name="line36"></a>&nbsp;
<a name="line37"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line38"></a>     *
<a name="line39"></a>     * @var DOMXPath
<a name="line40"></a>     */</span>
<a name="line41"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$xPath</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<a name="line42"></a>&nbsp;
<a name="line43"></a>&nbsp;
<a name="line44"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line45"></a>    <span style="color: #666666; font-style: italic;">/* Constructors                                                            */</span>
<a name="line46"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line47"></a>&nbsp;
<a name="line48"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseXML</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line49"></a>        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXML</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$responseXML</span><span style="color: #339933;">;</span>
<a name="line50"></a>&nbsp;
<a name="line51"></a>        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasServerResponsed</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line52"></a>            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiResponseException<span style="color: #009900;">&#40;</span>
<a name="line53"></a>            <span style="color: #0000ff;">'no response from: \''</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\''</span><span style="color: #339933;">,</span>
<a name="line54"></a>            <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span>
<a name="line55"></a>            <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line56"></a>        <span style="color: #009900;">&#125;</span>
<a name="line57"></a>&nbsp;
<a name="line58"></a>        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isException</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line59"></a>            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handleExceptionResponse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line60"></a>        <span style="color: #009900;">&#125;</span>
<a name="line61"></a>    <span style="color: #009900;">&#125;</span>
<a name="line62"></a>&nbsp;
<a name="line63"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line64"></a>    <span style="color: #666666; font-style: italic;">/* Public methods                                                          */</span>
<a name="line65"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line66"></a>&nbsp;
<a name="line67"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line68"></a>     *
<a name="line69"></a>     * @param string $query XPath query
<a name="line70"></a>     * @return mixed
<a name="line71"></a>     */</span>
<a name="line72"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line73"></a>        <span style="color: #000088;">$rawValue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/text()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wholeText</span><span style="color: #339933;">;</span>
<a name="line74"></a>&nbsp;
<a name="line75"></a>        <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line76"></a>            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'int'</span><span style="color: #339933;">:</span>
<a name="line77"></a>                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line78"></a>                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line79"></a>&nbsp;
<a name="line80"></a>            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'float'</span><span style="color: #339933;">:</span>
<a name="line81"></a>                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line82"></a>                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line83"></a>&nbsp;
<a name="line84"></a>            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'bool'</span><span style="color: #339933;">:</span>
<a name="line85"></a>                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>bool<span style="color: #009900;">&#41;</span><span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line86"></a>                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line87"></a>&nbsp;
<a name="line88"></a>            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<a name="line89"></a>                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line90"></a>        <span style="color: #009900;">&#125;</span>
<a name="line91"></a>&nbsp;
<a name="line92"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<a name="line93"></a>    <span style="color: #009900;">&#125;</span>
<a name="line94"></a>&nbsp;
<a name="line95"></a>&nbsp;
<a name="line96"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line97"></a>     *
<a name="line98"></a>     * @return boolean
<a name="line99"></a>     */</span>
<a name="line100"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> wasSuccessful<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line101"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/success'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'true'</span><span style="color: #339933;">;</span>
<a name="line102"></a>    <span style="color: #009900;">&#125;</span>
<a name="line103"></a>&nbsp;
<a name="line104"></a>&nbsp;
<a name="line105"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line106"></a>     *
<a name="line107"></a>     * @param array $queries
<a name="line108"></a>     * @return array
<a name="line109"></a>     */</span>
<a name="line110"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCollection<span style="color: #009900;">&#40;</span><span style="color: #000088;">$queries</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line111"></a>        <span style="color: #000088;">$collection</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line112"></a>        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$queries</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$collectionKey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line113"></a>            <span style="color: #000088;">$rawValue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/text()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wholeText</span><span style="color: #339933;">;</span>
<a name="line114"></a>&nbsp;
<a name="line115"></a>            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_string"><span style="color: #990000;">is_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$collectionKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line116"></a>                <span style="color: #000088;">$index</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$collectionKey</span><span style="color: #339933;">;</span>
<a name="line117"></a>                <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line118"></a>            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<a name="line119"></a>                <span style="color: #000088;">$index</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$collectionKey</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<a name="line120"></a>&nbsp;
<a name="line121"></a>                <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$collectionKey</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line122"></a>                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'bool'</span><span style="color: #339933;">:</span>
<a name="line123"></a>                        <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>bool<span style="color: #009900;">&#41;</span><span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line124"></a>                        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line125"></a>&nbsp;
<a name="line126"></a>                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'int'</span><span style="color: #339933;">:</span>
<a name="line127"></a>                        <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line128"></a>                        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line129"></a>&nbsp;
<a name="line130"></a>                    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'float'</span><span style="color: #339933;">:</span>
<a name="line131"></a>                        <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line132"></a>                        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line133"></a>&nbsp;
<a name="line134"></a>                    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<a name="line135"></a>                        <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rawValue</span><span style="color: #339933;">;</span>
<a name="line136"></a>                        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line137"></a>                <span style="color: #009900;">&#125;</span>
<a name="line138"></a>            <span style="color: #009900;">&#125;</span>
<a name="line139"></a>&nbsp;
<a name="line140"></a>            <span style="color: #000088;">$collection</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$index</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<a name="line141"></a>        <span style="color: #009900;">&#125;</span>
<a name="line142"></a>&nbsp;
<a name="line143"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$collection</span><span style="color: #339933;">;</span>
<a name="line144"></a>    <span style="color: #009900;">&#125;</span>
<a name="line145"></a>&nbsp;
<a name="line146"></a>&nbsp;
<a name="line147"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getSet<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line148"></a>        <span style="color: #000088;">$resultSet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line149"></a>&nbsp;
<a name="line150"></a>        <span style="color: #000088;">$listLength</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$resultSet</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">length</span><span style="color: #339933;">;</span>
<a name="line151"></a>        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$listLength</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line152"></a>            <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line153"></a>        <span style="color: #009900;">&#125;</span>
<a name="line154"></a>&nbsp;
<a name="line155"></a>        <span style="color: #000088;">$returnSet</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line156"></a>        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$listIndex</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$listIndex</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$listLength</span><span style="color: #339933;">;</span> <span style="color: #000088;">$listIndex</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line157"></a>            <span style="color: #000088;">$element</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$resultSet</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$listIndex</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line158"></a>            <span style="color: #000088;">$returnSet</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiResponse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ownerDocument</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$element</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line159"></a>        <span style="color: #009900;">&#125;</span>
<a name="line160"></a>&nbsp;
<a name="line161"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$returnSet</span><span style="color: #339933;">;</span>
<a name="line162"></a>    <span style="color: #009900;">&#125;</span>
<a name="line163"></a>&nbsp;
<a name="line164"></a>&nbsp;
<a name="line165"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line166"></a>     *
<a name="line167"></a>     * @return string An XML representation of the server response
<a name="line168"></a>     */</span>
<a name="line169"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toXML<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line170"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseDOM</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line171"></a>    <span style="color: #009900;">&#125;</span>
<a name="line172"></a>&nbsp;
<a name="line173"></a>&nbsp;
<a name="line174"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line175"></a>     *
<a name="line176"></a>     * @return string returns toXML()
<a name="line177"></a>     */</span>
<a name="line178"></a>    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line179"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line180"></a>    <span style="color: #009900;">&#125;</span>
<a name="line181"></a>&nbsp;
<a name="line182"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line183"></a>    <span style="color: #666666; font-style: italic;">/* Protected methods                                                       */</span>
<a name="line184"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line185"></a>&nbsp;
<a name="line186"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line187"></a>    <span style="color: #666666; font-style: italic;">/* Private methods                                                         */</span>
<a name="line188"></a>    <span style="color: #666666; font-style: italic;">/***************************************************************************/</span>
<a name="line189"></a>&nbsp;
<a name="line190"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line191"></a>     * Did the server respond at all?
<a name="line192"></a>     *
<a name="line193"></a>     * @param string $serverResponse
<a name="line194"></a>     * @return boolean
<a name="line195"></a>     */</span>
<a name="line196"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> hasServerResponsed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line197"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXML</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<a name="line198"></a>    <span style="color: #009900;">&#125;</span>
<a name="line199"></a>&nbsp;
<a name="line200"></a>&nbsp;
<a name="line201"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line202"></a>     *
<a name="line203"></a>     * @throws HR_apiResponseException
<a name="line204"></a>     * @return DOMDocument
<a name="line205"></a>     */</span>
<a name="line206"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> responseDOM<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line207"></a>        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseDOM</span> instanceof DOMDocument<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line208"></a>            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseDOM</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'utf-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line209"></a>            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseDOM</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXML</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line210"></a>                <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiResponseException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'API server returned malformed response'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">101</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXML</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line211"></a>            <span style="color: #009900;">&#125;</span>
<a name="line212"></a>        <span style="color: #009900;">&#125;</span>
<a name="line213"></a>&nbsp;
<a name="line214"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseDOM</span><span style="color: #339933;">;</span>
<a name="line215"></a>    <span style="color: #009900;">&#125;</span>
<a name="line216"></a>&nbsp;
<a name="line217"></a>&nbsp;
<a name="line218"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line219"></a>     *
<a name="line220"></a>     * @return DOMXPath
<a name="line221"></a>     */</span>
<a name="line222"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> responseXpath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line223"></a>        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xPath</span> instanceof DOMXPath<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line224"></a>            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xPath</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMXPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseDOM</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line225"></a>        <span style="color: #009900;">&#125;</span>
<a name="line226"></a>&nbsp;
<a name="line227"></a>        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">xPath</span><span style="color: #339933;">;</span>
<a name="line228"></a>    <span style="color: #009900;">&#125;</span>
<a name="line229"></a>&nbsp;
<a name="line230"></a>&nbsp;
<a name="line231"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line232"></a>     * Does this response represent an exception?
<a name="line233"></a>     *
<a name="line234"></a>     * @return boolean
<a name="line235"></a>     */</span>
<a name="line236"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> isException<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line237"></a>        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/exception'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line238"></a>    <span style="color: #009900;">&#125;</span>
<a name="line239"></a>&nbsp;
<a name="line240"></a>&nbsp;
<a name="line241"></a>    <span style="color: #009933; font-style: italic;">/**
<a name="line242"></a>     * Process an XML-based exception response from the API
<a name="line243"></a>     * and throw a local PHP exception
<a name="line244"></a>     *
<a name="line245"></a>     * Common exceptions are handled and thrown here. All others
<a name="line246"></a>     * are thrown as generic unknown API exceptions to be handled
<a name="line247"></a>     * by whichever class extends the api class.
<a name="line248"></a>     *
<a name="line249"></a>     */</span>
<a name="line250"></a>    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleExceptionResponse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line251"></a>        <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/exception/type/text()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wholeText</span><span style="color: #339933;">;</span>
<a name="line252"></a>        <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/exception/message/text()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wholeText</span><span style="color: #339933;">;</span>
<a name="line253"></a>        <span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">responseXpath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/exception/code/text()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wholeText</span><span style="color: #339933;">;</span>
<a name="line254"></a>&nbsp;
<a name="line255"></a>        <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<a name="line256"></a>            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'database'</span><span style="color: #339933;">:</span>
<a name="line257"></a>                <span style="color: #000088;">$exceptionMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'database connection failure'</span><span style="color: #339933;">;</span>
<a name="line258"></a>                <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiDatabaseException<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line259"></a>                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line260"></a>&nbsp;
<a name="line261"></a>            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'system'</span><span style="color: #339933;">:</span>
<a name="line262"></a>                <span style="color: #000088;">$exceptionMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'system failure'</span><span style="color: #339933;">;</span>
<a name="line263"></a>                <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiBackendSystemException<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line264"></a>                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line265"></a>&nbsp;
<a name="line266"></a>            <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'access'</span><span style="color: #339933;">:</span>
<a name="line267"></a>                <span style="color: #000088;">$exceptionMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'access failure'</span><span style="color: #339933;">;</span>
<a name="line268"></a>                <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiAccessException<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line269"></a>&nbsp;
<a name="line270"></a>            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<a name="line271"></a>                <span style="color: #000088;">$exception</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HR_apiResponseUnhandledException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Unhandled API exception'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line272"></a>                <span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setApiExceptionDetails</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a name="line273"></a>&nbsp;
<a name="line274"></a>                <span style="color: #b1b100;">throw</span> <span style="color: #000088;">$exception</span><span style="color: #339933;">;</span>
<a name="line275"></a>                <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<a name="line276"></a>        <span style="color: #009900;">&#125;</span>
<a name="line277"></a>    <span style="color: #009900;">&#125;</span>
<a name="line278"></a>&nbsp;
<a name="line279"></a><span style="color: #009900;">&#125;</span>
<a name="line280"></a>&nbsp;
<a name="line281"></a><span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<div class="header">
<h1>Hosting Reborn API PHP Library</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source/hr_apiresponse.class.php.html" target="_top">No frames</a>
</div>
<hr>

<p id="footer">This document was generated by <a href="http://peej.github.com/phpdoctor/">PHPDoctor: The PHP Documentation Creator</a></p>

</body>

</html>